import pygame

from Action.Walk import DirWalkByAImage, WalkDir


class WalkSoldier(pygame.sprite.Sprite):
    rect = ()
    hp = 100
    name = '某军'
    pos_x = 100
    pos_y = 300
    image_width = 50
    image_height = 100

    walk_action = None
    rect = ()

    def __init__(self, work_path: str, pos_x, pos_y, name, hp):
        super(WalkSoldier, self).__init__()
        self.walk_action = DirWalkByAImage(work_path,
                                           self.image_width, self.image_height, True)
        self.walk_action.set_dir(WalkDir.down)
        self.pos_x = pos_x
        self.pos_y = pos_y
        self.name = name
        self.hp = hp
        self.rect = pygame.Rect(self.pos_x - 5, self.pos_y -10, self.image_width-10, self.image_height-20)

    # 0 下 1 左  2 右 3 上
    def run(self, down_flag, key_list):
        if key_list[pygame.K_DOWN]:
            self.walk_action.set_dir(WalkDir.down)
            self.pos_y += 5
        elif key_list[pygame.K_UP]:
            self.walk_action.set_dir(WalkDir.up)
            self.pos_y -= 5
        elif key_list[pygame.K_LEFT]:
            self.walk_action.set_dir(WalkDir.left)
            self.pos_x -= 5
        elif key_list[pygame.K_RIGHT]:
            self.walk_action.set_dir(WalkDir.right)
            self.pos_x += 5

    def draw(self, surface: pygame.Surface, x, y):
        """
        绘制
        :param surface:
        :param x:
        :param y:
        :return:
        """
        current_image = self.walk_action.get_image()
        surface.blit(current_image, (self.pos_x - x, self.pos_y - y))